// @vue/component
import {Login} from "../../api/user.js"
import {mixin} from "../../utils/mixins";
export default {
    name: 'Login',

    components: {},

    mixins: [mixin],

    props: {},

    data () {
        return {
            loginForm: {
                name: 'admin',
                password: '123456'
            },
            redirect: undefined,
            formRules: {
                name: [
                    { required: true, message: '请输入登录名', trigger: 'blur' },
                    { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入登录密码', trigger: 'blur' },
                    { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
                ]
            }
        }
    },

    computed: {},

    watch: {},

    created () {},

    methods: {
        confirm () {
            this.$refs.formRef.validate(valid => {
                if (valid) {
                    let username = this.loginForm.name;
                  Login(this.loginForm)
                        .then((res) => {
                            console.log(res)
                            localStorage.setItem("username",username)
                            localStorage.setItem("token",res.token)
                            localStorage.setItem("permission",res.permission)
                            this.$router.push("/index")
                            this.notify("登录成功","success");
                        })
                        .catch(err => err)
                }
            })
        },
        resetForm () {
            this.$refs.formRef.resetFields()
        }

    }
}
